
import createPersistedState   from 'vuex-persistedstate' //解决Vuex持久化插件-在F5刷新页面后数据不见的问题

Vue.use(Vuex)

const store = new Vuex.Store({
	state:{
		//用户名
		username        : '',
		//左侧菜单data
		menudata        : [],
		//等待状态
		loading         : false,//设置为false
		//header消息数
		messageNum      : '',
		//当前用户操作权限按钮
		button_limit    : [],
		//当前打开的是 移动端 还是 pc 端
		isMobile        : false,
		//需要缓存的路由数组
		cacheRoute      : [],
	},
	getters:{
		username        : state => state.username,
		menudata        : state => state.menudata,
		loading         : state => state.loading,
		messageNum      : state => state.messageNum,
		button_limit    : state => state.button_limit,
		isMobile        : state => state.isMobile,
		cacheRoute      : state => state.cacheRoute,
	},
	mutations : {
		//用户名
		setusername(state,data){
			state.username = data
		},
		//左侧菜单data
		setmenudata(state,data){
			state.menudata = data
		},
		//加载状态改变
		showLoading(state){
	      state.loading = true 
	    },
	    hideLoading (state) {
	      state.loading = false
	    },
	    //当前用户收到的 消息数
	    setmessageNum(state,data) {
	      state.messageNum = data
	    },
	    //当前用户 拥有的页面操作权限 
	    setbutton_limit(state,data) {
	      state.button_limit = data
	    },

	    //当前打开的是 移动端 还是 pc 端
	    setisMobile(state,data) {
	      state.isMobile = data
	    },
	    //需要缓存的路由数组
	    setcacheRoute(state,data) {
	      state.cacheRoute = data
	    },

	},
	actions:{

	},
	plugins: [createPersistedState({
		//默认存储到localStorage
		//想要存储到sessionStorage，配置如下
		storage: window.sessionStorage
	})]
})

export default store